package com.wondedDream.controller.web;

import com.wondedDream.model.ResultData;
import com.wondedDream.model.User;
import com.wondedDream.repository.PhoneNumberRepository;
import com.wondedDream.service.UserService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;
import java.util.Map;

@RestController(value = "webUserController")
@RequestMapping("/web/users")
@Api(description = "客户端-用户模块")
public class WeChatLoginController {

    @Autowired
    private UserService userService;

    @Autowired
    private PhoneNumberRepository phoneNumberRepository;
    @Autowired
    private RestTemplate restTemplate;


    private static final String WECHAT_APPID = "your_app_id";
    private static final String WECHAT_SECRET = "your_app_secret";

    // 注册新用户
    @PostMapping("/register")
    public User registerUser(@RequestBody User user) {
        return userService.saveUser(user);
    }

    // 获取用户信息
    @GetMapping("/{id}")
    public User getUserById(@PathVariable Integer id) {
        return userService.getUserById(id);
    }



    // 用户登录接口
    @GetMapping("/login")
    public ResultData login(@RequestParam String code, @RequestParam String encryptedData, @RequestParam String iv) {
        Map<String, Object> result = userService.login(code, encryptedData, iv);
        return new ResultData(result);
    }

    // 用户信息更新接口
    @PutMapping("/update")
    public User updateUser(@RequestBody User user) {
//        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
//        String openid = auth.getName(); // 获取当前用户的 openid
//        user.setOpenid(openid);
//        return userService.updateUser(user);
        return null;
    }

}